package com.jeesite.modules.ch.web;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.ch.entity.ChMyTask;
import com.jeesite.modules.ch.service.ChMyTaskService;

/**
 * ch_my_taskController
 * @author 李寒冰
 * @version 2025-10-15
 */
@Controller
@RequestMapping(value = "${adminPath}/ch/chMyTask")
public class ChMyTaskController extends BaseController {

	@Autowired
	private ChMyTaskService chMyTaskService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public ChMyTask get(String id, boolean isNewRecord) {
		return chMyTaskService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("ch:chMyTask:view")
	@RequestMapping(value = {"list", ""})
	public String list(ChMyTask chMyTask, Model model) {
		model.addAttribute("chMyTask", chMyTask);
		return "modules/ch/chMyTaskList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("ch:chMyTask:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<ChMyTask> listData(ChMyTask chMyTask, HttpServletRequest request, HttpServletResponse response) {
		chMyTask.setPage(new Page<>(request, response));
		Page<ChMyTask> page = chMyTaskService.findPage(chMyTask);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("ch:chMyTask:view")
	@RequestMapping(value = "form")
	public String form(ChMyTask chMyTask, Model model) {
		model.addAttribute("chMyTask", chMyTask);
		return "modules/ch/chMyTaskForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("ch:chMyTask:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated ChMyTask chMyTask) {
		chMyTaskService.save(chMyTask);
		return renderResult(Global.TRUE, text("保存ch_my_task成功！"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("ch:chMyTask:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(ChMyTask chMyTask) {
		chMyTaskService.delete(chMyTask);
		return renderResult(Global.TRUE, text("删除ch_my_task成功！"));
	}
	
}